package com.bl.weilan.api.controller.trade;

import com.bl.weilan.api.controller.BaseController;
import com.bl.weilan.common.ApiResponseBody;
import com.bl.weilan.dao.model.ReportEntity;
import com.bl.weilan.dao.model.TradeCEntity;
import com.bl.weilan.dao.model.TradeChartDetailEntity;
import com.bl.weilan.service.biz.report.ReportService;
import com.bl.weilan.service.biz.trade.TradeService;
import com.bl.weilan.service.biz.tradedetail.TradeDetailService;
import com.bl.weilan.service.vo.report.ReportListVo;
import com.bl.weilan.service.vo.tradeb.TradeBCListVo;
import com.bl.weilan.service.vo.tradeb.TradeBListVo;
import com.bl.weilan.service.vo.tradec.TradeCListVo;
import com.bl.weilan.service.vo.tradec.TradeVo;
import com.bl.weilan.service.vo.tradedetail.TradeDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by liangweikang on 19/7/14.
 */
@RestController
@Log4j2
@RequestMapping(value = {"/weilan/apis/trade"})
@Api(value = "行业相关", description = "行业相关")
public class TradeController extends BaseController {

    @Autowired
    TradeService tradeService;

    @Autowired
    TradeDetailService tradeDetailService;

    @ApiOperation(value = "根据一级行业id获取二三级行业列表", notes = "根据一级行业id获取二三级行业列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tradeaId", value = "tradea_Id", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/get_tradebc_list"})
    public ApiResponseBody<TradeBCListVo> gettradeBClist(
            @RequestParam(value = "tradeaId", required = true) String tradeaId,
            HttpServletRequest request) {

        TradeBCListVo tradeBListVo = tradeService.getTradeBCList(tradeaId);

        return ApiResponseBody.createSuccessBody(tradeBListVo);
    }

    @ApiOperation(value = "根据一级行业id获取二级行业列表", notes = "根据一级行业id获取二级行业列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tradeaId", value = "tradea_Id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_tradeb_list"})
    public ApiResponseBody<TradeBListVo> gettradeBlist(
            @RequestParam(value = "tradeaId", required = true) String tradeaId,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);

        TradeBListVo tradeBListVo = tradeService.getTradeBList(tradeaId, pageable);

        return ApiResponseBody.createSuccessBody(tradeBListVo);
    }


    @ApiOperation(value = "根据二级行业id获取三级行业列表", notes = "根据二级行业id获取三级行业列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tradebId", value = "tradeb_Id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_tradec_list"})
    public ApiResponseBody<TradeCListVo> gettradeClist(
            @RequestParam(value = "tradebId", required = true) String tradebId,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);

        TradeCListVo tradeCListVo = tradeService.getTradeCList(tradebId, pageable);

        return ApiResponseBody.createSuccessBody(tradeCListVo);
    }

    @ApiOperation(value = "行业详情信息", notes = "行业详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/get_detail"})
    public ApiResponseBody<TradeVo> gettradeClist(
            @RequestParam(value = "id", required = false, defaultValue = "1") String id,
             HttpServletRequest request) {


        TradeVo tradeVo = tradeService.getTradeDetail(id);

        return ApiResponseBody.createSuccessBody(tradeVo);
    }

    @ApiOperation(value = "行业图表信息", notes = "行业图表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/get_chart"})
    public ApiResponseBody<TradeDetailVo> gettradeChart(
            @RequestParam(value = "id", required = false, defaultValue = "1") String id,
            HttpServletRequest request) {


        TradeDetailVo tradeVo = tradeDetailService.getTradeBarDetailVo(id);

        return ApiResponseBody.createSuccessBody(tradeVo);
    }
}
